#include <iostream>
using namespace std;

class Shape
{
public:
    Shape(int x, int y)
        : _x(x), _y(y) {}
    virtual void draw()     //虚函数定义
    {
        cout << "draw Shape ";
        cout << "start (" << _x << "," << _y << ") " << endl;
    }

protected:
    int _x;
    int _y;
};

class Circle : public Shape
{
public:
    Circle(int x, int y, int r)
        : Shape(x, y), _r(r) {}
    void draw()             //子类虚函数覆写
    {
        cout << "draw Circle ";
        cout << "start (" << _x << "," << _y << ") ";
        cout << "raduis r = " << _r << endl;
    }

private:
    int _r;
};

class Rect : public Shape
{
public:
    Rect(int x, int y, int l, int w)
        : Shape(x, y), _len(l), _wid(w) {}
    void draw() 
    {
        cout << "draw Rect";
        cout << "start (" << _x << "," << _y << ") ";
        cout << "len = " << _len << " wid = " << _wid << endl;
    }

protected:
    int _len;
    int _wid;
};
int main()
{
    Circle c(1, 2, 4);
    Rect r(2, 3, 4, 5);
    Shape *ps;
    int choice;
    while (1) //一个父类对象指针，随指向子类对象的不同，动态的调用不同的函数，实现动多态。
    {
        scanf("%d", &choice);
        switch (choice)
        {
        case 1:
            ps = &c;
            ps->draw();
            break;
        case 2:
            ps = &r;
            ps->draw();
            break;
        }
    }
    return 0;
}